home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SAVESCRN.SWG / 0004_SAVE4.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  51 lines

  1. {
  2. I couldn't find your original message, but you could use this code fragment to
  3. save and restore a Text-mode screen.
  4. }
  5.  
  6. (* global Vars *)
  7. Var
  8.    vidSeg : Word;
  9.    oldScr : Array[0..3999] of Byte;
  10.  
  11. Function GetVidSeg : Word;
  12. Var
  13.    mode : Byte;
  14.    seg  : Word;
  15. begin
  16.      seg := 0;
  17.      mode := Mem[0 : $449];
  18.      if (mode = 7) then seg := $B000;
  19.      if (mode <= 3) then seg := $B800;
  20.      if (mode in [4..6]) or (mode > 7) then begin
  21.         (* the Program is not in the correct Text mode *)
  22.         Halt(1);  (* return errorlevel of 1 *)
  23.      end;
  24.      GetVidSeg := seg;
  25. end;
  26.  
  27. (* main Program *)
  28. begin
  29.      vidSeg := GetVidSeg;
  30.      Move(Mem[vidSeg : 0], oldScr[0], SizeOf(oldScr));
  31.      (* the above line copies 4000 Bytes starting at $B000 : 0 For mono.
  32.         or $B800 For colour into the Array 'oldScr' *)
  33.      ClrScr;
  34.      WriteLn('Press ENTER to restore the screen...');
  35.      Readln;
  36.      Move(oldScr[0], Mem[vidSeg : 0], SizeOf(oldScr));
  37.      (* the above line copies the Array to video memory to restore the
  38.         old screen *)
  39. end.
  40.  
  41. {
  42. As you can see, video memory starts at offset 0 of either of two segments.  If
  43. the computer is colour, Text screen memory starts at $B800 : 0000 and if the
  44. computer is mono/herc, it starts at $B000 : 0000.  It is 4000 Bytes long.  Why?
  45.  Because there are 2000 Characters on the screen (80 x 25), and each Character
  46. gets a colour attribute (foreground, background, (non)blinking).  The top-left
  47. Character, at row 1, column 1, is [vidSeg] : 0, and the next Byte,[vidSeg] : 1,
  48. is the attribute For the Character, so the memory is laid out like this:
  49.  
  50. (offset 0) Char, attr, Char, attr, Char, attr.......Char, attr (offset 3999)
  51. }